﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Jemgine.Engine.Scripts
{
    [Category("System"), Node]
   public class Toggle: Data.ScriptNode
    {
        public enum States
        {
            On,
            Off
        };

        public States State { get; set; }

       public Toggle()
       {
           AddInput("In", null);
           AddInput("Toggle", null);
           AddOutput("IfOn", null);
           AddOutput("IfOff", null);

           State = States.On;
       }

       public override void FireTerminal(int InputID, Data.ScriptPayload Payload)
       {
           switch (InputID)
           {
               case 1:
                   if (State == States.Off)
                       State = States.On;
                   else
                       State = States.Off;
                   break;
               case 0:
                   if (State == States.On)
                       OutputTerminals[0].Fire(Payload);
                   else
                       OutputTerminals[1].Fire(Payload);
                   break;
           }
       }

      
    }
}
